//
//  FGActivityTemplateView.m
//  lite
//
//  Created by feige on 2022/11/2.
//

#import "FGActivityTemplateView.h"
#import "UIView+FGLayout.h"
#import "FGResources.h"
#import <SDWebImage/SDWebImage.h>

@interface FGActivityTemplateView()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) id templateData;
@end

@implementation FGActivityTemplateView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        // imageView
        _imageView = [UIImageView new];
        _imageView.clipsToBounds = YES;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_imageView];
        
        // titleLabel
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        [self addSubview:_titleLabel];
        
        // subtitleLabel
        _subtitleLabel = [UILabel new];
        _subtitleLabel.numberOfLines = 2;
        _subtitleLabel.font = [UIFont systemFontOfSize:14];
        _subtitleLabel.textColor = [UIColor lightGrayColor];
        [self addSubview:_subtitleLabel];
        
        _imageView.image = [FGResources getImageFromMessage:@"placeholder_image"];
        _titleLabel.text = @"活动标题1";
        _subtitleLabel.text = @"描述信息描述信息描述信息描述信息描述信息描述信息";
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _titleLabel.frame = CGRectMake(10, 10, self.mm_w - 20, 22);
    
    _subtitleLabel.mm_sizeToFit().mm_left(_titleLabel.mm_x).mm_width(self.mm_w - 20).mm_top(_titleLabel.mm_maxY + 8);
    
    _imageView.frame = CGRectMake(10, 87, self.mm_w - 20, 132);
}

#pragma mark - Rewrite Mehtod

- (void)fillData:(id)templateData {
    self.templateData = templateData;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:[self.templateData valueForKeyPath:@"data.imageUrl"]] placeholderImage:[FGResources getImageFromMessage:@"placeholder_image"]];
    self.titleLabel.text = [self.templateData valueForKeyPath:@"data.title"];
    self.subtitleLabel.text = [self.templateData valueForKeyPath:@"data.description"];
}

/*
 {
     "isView":false,
     "id":12,
     "data":{
         "linkUrl":"https:\/\/element.eleme.io\/#\/zh-CN\/component\/icon",
         "id":12,
         "updateTime":"2022-10-25 17:02:05",
         "title":"也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊",
         "imageUrl":"https:\/\/testfebookpic.oss-cn-hangzhou.aliyuncs.com\/febookimg\/202210\/3_3930ca14f6194d3fb80160e664d304b8.png",
         "description":"这个是elementui的ui库也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊",
         "websiteId":1,
         "createTime":"2022-10-25 17:02:05",
         "companyId":1
     },
     "children":null,
     "type":4,
     "tips":null,
     "name":"也是活动啊也是活动啊也是活动啊也是活动啊也是活动啊",
     "pid":4
 }
 */

@end
